<template>
	<view class="changeage">
		<view class="top" v-if="muban_url">
			<view class="top_mid">
				<image :src="muban_url" mode="aspectFit" class="imuban"></image>
			</view>
		</view>
		<view class="" v-else style="width: 697rpx; height: 500rpx; margin: 10rpx auto">
			<cmp :beforeImageUrl="img1" :afterImageUrl="img2" width="697" height="500"></cmp>
		</view>

		<!-- 		<button class="btn" @click="startBianLian" :loading="loadding" :disabled="loadding"
			v-if="muban_url">开始处理</button> -->
		<button class="btn" @click="handleQuShuiYing">选择图片</button>
		<text v-if="price" class="t_price">{{ price }}</text>
		<view class="tip">
			<text class="t1">温馨提示</text>
			<text class="t2">
				1、您在使用本服务时，应当遵守相关法律法规的要求以及本平台的相关服务协议，不得将本服务用于非法目的，不得利用本服务从事违法法律法规或侵犯他人合法权益的行为
				您在使用本服务时，应当确保您自身或者您应用的用户使用、上传、发布的照片、素材等信息内容，已取得相关权利人的合法授权，不存在侵犯他人肖像权、版权等合法权益的情形，亦不存在违反相关法律、法规、政策的规定以及公序良俗等情形。
				您自行对您应用中由用户使用本服务产生的内容负责，保证其不违法相关法律、法规、政策的规定以及公序良俗等。
				您违法上述要求引发的任何纠纷由您自行负责，与本平台无关。本平台有权立即停止您在本平台中的一切服务并保留追究您法律责任的权利
			</text>
		</view>
	</view>
</template>

<script>
import { getUser, getAbilityPrice } from '@/src/utils/utils.js';
import { jumpto as jump } from '@/src/utils/utils.js';
import cmp from '@/components/FaceComparison.vue';
import {
		upload_file
	} from '@/src/utils/uni-fetch.js';
export default {
	components: {
		cmp,
	},
	data() {
		return {
			img1: 'https://sm.2sxzw.com/mgmg/jiabin01/ability/before-1.529e7b48.jpeg',
			img2: 'https://sm.2sxzw.com/mgmg/jiabin01/ability/after-1.1862298f.jpeg',
			muban_url: null,
			muban_id: null,
			loadding: false,
			price: null,
		};
	},
	onLoad() {
		this.init_price();
	},
	methods: {
		async init_price() {
			try {
				this.price = await getAbilityPrice('ImageQuShuiYin');
			} catch (e) {
				console.log(e);
			}
		},
		// handleQuShuiYing() {
		// 	jump(`/src/pages/Ability/qushuiyin/ImageQuShuiYin/ImageQuShuiYin`);
		// },
		handleQuShuiYing() {
			let _this = this;
			uni.chooseImage({
				sizeType: ['compressed', 'original'],
				count: 1,
				success: (img) => {
					uni.getImageInfo({
						src: img.tempFilePaths[0],
						success: (res) => {
							//jump(`/src/pages/Ability/qushuiyin/ImageQuShuiYin/ImageQuShuiYin?bgImage=${JSON.stringify(res)}`);
							_this.up_file(img.tempFilePaths[0], res)
						},
					});
				},
			});
		},
		async up_file(file_path, image_info) {
			try {
				let result = await upload_file({
					url: '/huanlian/up_image2/',
					file: {
						name: 'image',
						uri: file_path
					},
					formData: {
						img_type: 1
					}
				});
				if (result.err_no == 0) {
					jump(
						`/src/pages/Ability/qushuiyin/ImageQuShuiYin/ImageQuShuiYin?bgImage=${JSON.stringify(image_info)}`
						);
		
				}
			} catch (e) {
				if (!e) return
				uni.showModal({
					content: e.errMsg || e.message,
					showCancel: false
				});
			}
		}
	},
};
</script>

<style lang="scss" scoped>
@import 'QuShuiYin.scss';
</style>
